package io.yizoo.system.controller.flow;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.elm.core.CoreController;

import java.io.IOException;
import java.util.*;


import io.elm.core.CoreMapper;
import io.elm.core.DMaker;
import io.yizoo.business.entity.biz_hrm_ei_basic;
import io.yizoo.core.flow.FlowDesigner;
import io.yizoo.core.flow.FlowType;
import io.yizoo.system.entity.*;
import io.yizoo.system.mapper.sys_flowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/flow/flow")
public class flowController extends CoreController {

    @Autowired
    private CoreMapper coreMapper;

    @Autowired
    private FlowDesigner dfTool;

    @Autowired
    private sys_flowMapper flowMapper;

    @PostMapping("/GetFlowListPage_OnCanvas")
    public Object GetFlowListPage_OnCanvas(@RequestBody String jsonStr) {
        return JsonResultPage(dfTool.GetFlowListPage_OnCanvas(jsonStr));
    }

    @PostMapping("/GetFlowList")
    public Object GetFlowList(@RequestBody String jsonStr) {
        return dfTool.GetFlowList(jsonStr);
    }
    @PostMapping("/GetFlowCodeForCreate")
    public Object GetFlowCodeForCreate(@RequestBody String jsonStr) {
        return dfTool.GetFlowCodeForCreate(jsonStr);
    }
    @PostMapping("/GetSecForm")
    public Object GetSecForm(@RequestBody String jsonStr) {
        return dfTool.GetSecForm(jsonStr);
    }
    @PostMapping("/UpserFlowAndSecForm")
    public Object UpserFlowAndSecForm(@RequestBody String jsonStr) {
        return dfTool.UpserFlowAndSecForm(jsonStr);
    }
    @PostMapping("/UpsertFlowSecForm")
    public Object UpsertFlowSecForm(@RequestBody String jsonStr) {
        return  dfTool.UpsertFlowSecForm(jsonStr);
    }
    @PostMapping("/DeleteFlow")
    public Object DeleteFlow(@RequestBody String jsonStr) {
        ObjectNode data = Ctor.getObjectNode(jsonStr);
        String flow_id = data.get("id").asText();
        return dfTool.DeleteFlow(flow_id);
    }
    @PostMapping("/GetDataForNodeCheckEdit")
    public Object GetDataForNodeCheckEdit() {
        return dfTool.GetDataForNodeCheckEdit();
    }

    @PostMapping("/GetFlowParamList")
    public Object GetFlowParamList(@RequestBody String jsonStr) {
        return dfTool.GetFlowParamList(jsonStr);
    }
    @PostMapping("/UpsertFlowParam")
    public Object UpsertFlowParam(@RequestBody String jsonStr) {
        return dfTool.UpsertFlowParam(jsonStr);
    }
    @PostMapping("/DeleteParam")
    public Object DeleteParam(@RequestBody String jsonStr) {
        return dfTool.DeleteParam(jsonStr);
    }

    /////

}
